<template>
	<div class="tts-broadcast-table-warpper">
		<el-table :data="tableData" style="width: 100%" border empty-text="你还未添加TTS辅助播报" stripe >
			<el-table-column label="序号" width="50" align="center" prop="id" type="index"></el-table-column>
			<el-table-column prop="title" label="标题" width="auto" align="center"> </el-table-column>
			<!-- <el-table-column prop="content" label="TTS辅助播报" width="auto" align="center"> </el-table-column> -->
			<el-table-column prop="createdAt" label="创建日期" width="auto" align="center" :formatter="formatTime"> </el-table-column>
			<el-table-column label="操作" width="180" align="center">
				<template slot-scope="scope">
					<div class="btn-box">
						<el-button type="primary" @click="modifyTtsBroadcast(scope.row)" size="mini" :disabled="!canEdit">修改</el-button>
						<el-button type="danger" @click="delTtsBroadcast(scope.row)" size="mini" :disabled="!canEdit">删除</el-button>
					</div>
				</template>
			</el-table-column>
		</el-table>
	</div>
</template>

<script>
export default {
	props: {
		tableData: {
			type: Array,
			default: () => []
		}
	},
	data() {
		return {
			canEdit: false
		};
	},
	mounted() {
		this.canEdit = this.$route.query.canEdit === 'true';
	},
	methods: {
		formatTime(row){
			return this.$moment(row.createdAt).format('YYYY-MM-DD HH:mm:ss');
		},
		modifyTtsBroadcast(data) {
			this.$emit('modifyTtsBroadcast', data);
		},
		delTtsBroadcast(data) {
			this.$confirm(`确定要删除 "${data.title}" TTS辅助播报吗?`, '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			})
				.then(() => {
					this.$emit('delTtsBroadcast', data);
				})
				.catch(e => {
					console.log(e);
				});
		}
	}
};
</script>

<style lang="less" scoped>
.tts-broadcast-table-warpper {
}
</style>
